/**
 *  对 uni 提供的一些方法使用 promise 进行二次封装
*/
export function uniPromisify(fn) {
	return (options) => new Promise((resolve, reject) => {
		fn({
			...options,
			success: resolve,
			fail: reject
		})
	})
}

/**
 * 获取图片路径
*/
export function getAssetsImage(path) {
	return new URL(`../assets/images/${path}`, import.meta.url).href
}

// 获取随机字符串
export function randomString(length = 8) {
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
  let result = ''
  for (let i = 0; i < length; i++) {
    const index = Math.floor(Math.random() * chars.length)
    result += chars.charAt(index)
  }
  return result
}